home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 20 / Cream of the Crop 20 (Terry Blount) (1996).iso / os2 / sysb091a.zip / sysbench / src / dhry_1.c next >
C/C++ Source or Header  |  1995-12-31  |  15KB  |  508 lines

  1. /*
  2.  ****************************************************************************
  3.  *
  4.  *                   "DHRYSTONE" Benchmark Program
  5.  *                   -----------------------------
  6.  *
  7.  *  Version:    C, Version 2.1
  8.  *
  9.  *  File:       dhry_1.c (part 2 of 3)
  10.  *
  11.  *  Date:       May 25, 1988
  12.  *
  13.  *  Author:     Reinhold P. Weicker
  14.  *
  15.  ****************************************************************************
  16.  */
  17.  
  18. #include "dhry.h"
  19.  
  20. /* Global Variables: */
  21.  
  22. Rec_Pointer     Ptr_Glob,
  23.                 Next_Ptr_Glob;
  24. int             Int_Glob;
  25. Boolean         Bool_Glob;
  26. char            Ch_1_Glob,
  27.                 Ch_2_Glob;
  28. int             Arr_1_Glob [50];
  29. int             Arr_2_Glob [50] [50];
  30.  
  31. /*extern char     *malloc ();*/
  32. Enumeration     Func_1 ();
  33.   /* forward declaration necessary since Enumeration may not simply be int */
  34. void Proc_1 (), Proc_2 (), Proc_3 (), Proc_4 (), Proc_5 ();
  35.  
  36. #ifndef REG
  37.         Boolean Reg = false;
  38. #define REG
  39.         /* REG becomes defined as empty */
  40.         /* i.e. no register variables   */
  41. #else
  42.         Boolean Reg = true;
  43. #endif
  44.  
  45. /* variables for time measurement: */
  46.  
  47. #ifdef TIMES
  48. struct tms      time_info;
  49. extern  int     times ();
  50.                 /* see library function "times" */
  51. #define Too_Small_Time (2*HZ)
  52.                 /* Measurements should last at least about 2 seconds */
  53. #endif
  54.  
  55. #ifdef TIME
  56. extern long     time();
  57.                 /* see library function "time"  */
  58. #define Too_Small_Time 2
  59.                 /* Measurements should last at least 2 seconds */
  60. #endif
  61.  
  62. #ifdef CLOCK
  63. extern clock_t    clock();
  64. #define Too_Small_Time (2*HZ)
  65. #define DURATION 5
  66. #endif
  67.  
  68. #ifdef OS2TMR
  69. extern long start_alarm(long), start_timer(void *), stop_timer(void*, long);
  70. char Run_Time[8];
  71. #ifdef HZ
  72. #undef HZ
  73. #endif
  74. #define HZ 1000
  75. #define Too_Small_Time (2*HZ)
  76. #define DURATION 5
  77. #define main dhry_main
  78. #endif
  79.  
  80. #ifdef DURATION
  81. #include <signal.h>
  82. #endif
  83.  
  84. unsigned long   Number_Of_Runs;
  85. long            User_Time;
  86. unsigned long   Microseconds,
  87.                 Totalseconds,
  88.                 Dhrystones_Per_Second;
  89.  
  90. /* end of variables for time measurement */
  91.  
  92. long dhry_stone(void)
  93. {
  94.     One_Fifty       Int_1_Loc;
  95.   REG   One_Fifty       Int_2_Loc;
  96.     One_Fifty       Int_3_Loc;
  97.   REG   char            Ch_Index;
  98.     Enumeration     Enum_Loc;
  99.     Str_30          Str_1_Loc;
  100.     Str_30          Str_2_Loc;
  101.   REG   unsigned long   Run_Index;
  102.  
  103.   long Begin_Time, End_Time;
  104.                 
  105.   /* Initializations */
  106.  
  107.   Next_Ptr_Glob = (Rec_Pointer) malloc (sizeof (Rec_Type));
  108.   Ptr_Glob = (Rec_Pointer) malloc (sizeof (Rec_Type));
  109.  
  110.   Ptr_Glob->Ptr_Comp                    = Next_Ptr_Glob;
  111.   Ptr_Glob->Discr                       = Ident_1;
  112.   Ptr_Glob->variant.var_1.Enum_Comp     = Ident_3;
  113.   Ptr_Glob->variant.var_1.Int_Comp      = 40;
  114.   strcpy (Ptr_Glob->variant.var_1.Str_Comp,
  115.           "DHRYSTONE PROGRAM, SOME STRING");
  116.   strcpy (Str_1_Loc, "DHRYSTONE PROGRAM, 1'ST STRING");
  117.  
  118.   Arr_2_Glob [8][7] = 10;
  119.         /* Was missing in published program. Without this statement,    */
  120.         /* Arr_2_Glob [8][7] would have an undefined value.             */
  121.         /* Warning: With 16-Bit processors and Number_Of_Runs > 32000,  */
  122.         /* overflow may occur for this array element.                   */
  123.  
  124.   /***************/
  125.   /* Start timer */
  126.   /***************/
  127.  
  128. #ifdef TIMES
  129.   times (&time_info);
  130.   Begin_Time = (long) time_info.tms_utime;
  131. #endif
  132. #ifdef TIME
  133.   Begin_Time = time ( (long *) 0);
  134. #endif
  135. #ifdef CLOCK
  136.   Begin_Time = clock();
  137. #endif
  138. #ifdef OS2TMR
  139.   Begin_Time = 0;
  140.   start_timer(&Run_Time);
  141. #endif
  142.  
  143.   for (Run_Index = 1; Run_Index <= Number_Of_Runs; ++Run_Index)
  144.   {
  145.  
  146.     Proc_5();
  147.     Proc_4();
  148.       /* Ch_1_Glob == 'A', Ch_2_Glob == 'B', Bool_Glob == true */
  149.     Int_1_Loc = 2;
  150.     Int_2_Loc = 3;
  151.     strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 2'ND STRING");
  152.     Enum_Loc = Ident_2;
  153.     Bool_Glob = ! Func_2 (Str_1_Loc, Str_2_Loc);
  154.       /* Bool_Glob == 1 */
  155.     while (Int_1_Loc < Int_2_Loc)  /* loop body executed once */
  156.     {
  157.       Int_3_Loc = 5 * Int_1_Loc - Int_2_Loc;
  158.         /* Int_3_Loc == 7 */
  159.       Proc_7 (Int_1_Loc, Int_2_Loc, &Int_3_Loc);
  160.         /* Int_3_Loc == 7 */
  161.       Int_1_Loc += 1;
  162.     } /* while */
  163.       /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
  164.     Proc_8 (Arr_1_Glob, Arr_2_Glob, Int_1_Loc, Int_3_Loc);
  165.       /* Int_Glob == 5 */
  166.     Proc_1 (Ptr_Glob);
  167.     for (Ch_Index = 'A'; Ch_Index <= Ch_2_Glob; ++Ch_Index)
  168.                              /* loop body executed twice */
  169.     {
  170.       if (Enum_Loc == Func_1 (Ch_Index, 'C'))
  171.           /* then, not executed */
  172.         {
  173.         Proc_6 (Ident_1, &Enum_Loc);
  174.         strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 3'RD STRING");
  175.         Int_2_Loc = Run_Index;
  176.         Int_Glob = Run_Index;
  177.         }
  178.     }
  179.       /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
  180.     Int_2_Loc = Int_2_Loc * Int_1_Loc;
  181.     Int_1_Loc = Int_2_Loc / Int_3_Loc;
  182.     Int_2_Loc = 7 * (Int_2_Loc - Int_3_Loc) - Int_1_Loc;
  183.       /* Int_1_Loc == 1, Int_2_Loc == 13, Int_3_Loc == 7 */
  184.     Proc_2 (&Int_1_Loc);
  185.       /* Int_1_Loc == 5 */
  186.  
  187.   } /* loop "for Run_Index" */
  188.  
  189.   /**************/
  190.   /* Stop timer */
  191.   /**************/
  192.  
  193. #ifdef TIMES
  194.   times (&time_info);
  195.   End_Time = (long) time_info.tms_utime;
  196. #endif
  197. #ifdef TIME
  198.   End_Time = time ( (long *) 0);
  199. #endif
  200. #ifdef CLOCK
  201.   End_Time = clock();
  202. #endif
  203. #ifdef OS2TMR
  204.   End_Time = stop_timer(&Run_Time, HZ);
  205. #endif
  206. #ifdef DURATION
  207.   Number_Of_Runs = Run_Index - 1;
  208. #endif
  209.  
  210.   if (Int_Glob != 5)
  211.     return 0;
  212.   if (Bool_Glob != 1)
  213.     return 0;
  214.   if (Ch_1_Glob != 'A')
  215.     return 0;
  216.   if (Ch_2_Glob != 'B')
  217.     return 0;
  218.   if (Arr_1_Glob[8] != 7)
  219.     return 0;
  220.   if (Arr_2_Glob[8][7] != Number_Of_Runs + 10)
  221.     return 0;
  222.   if (Ptr_Glob->Discr != 0)
  223.     return 0;
  224.   if (Ptr_Glob->variant.var_1.Enum_Comp != 2)
  225.     return 0;
  226.   if (Ptr_Glob->variant.var_1.Int_Comp != 17)
  227.     return 0;
  228.   if (strcmp(Ptr_Glob->variant.var_1.Str_Comp, 
  229.          "DHRYSTONE PROGRAM, SOME STRING") != 0)
  230.     return 0;
  231.   if (Next_Ptr_Glob->Discr != 0)
  232.     return 0;
  233.   if (Next_Ptr_Glob->variant.var_1.Enum_Comp != 1)
  234.     return 0;
  235.   if (Next_Ptr_Glob->variant.var_1.Int_Comp != 18)
  236.     return 0;
  237.   if (strcmp(Next_Ptr_Glob->variant.var_1.Str_Comp, 
  238.          "DHRYSTONE PROGRAM, SOME STRING") != 0)
  239.     return 0;
  240.   if (Int_1_Loc != 5)
  241.     return 0;
  242.   if (Int_2_Loc != 13)
  243.     return 0;
  244.   if (Int_3_Loc != 7)
  245.     return 0;
  246.   if (Enum_Loc != 1)
  247.     return 0;
  248.   if (strcmp(Str_1_Loc, "DHRYSTONE PROGRAM, 1'ST STRING") != 0)
  249.     return 0;
  250.   if (strcmp(Str_2_Loc, "DHRYSTONE PROGRAM, 2'ND STRING") != 0)
  251.     return 0;
  252.  
  253.   return End_Time - Begin_Time;
  254. }
  255.  
  256. void alarm_handler(int sig)
  257. {
  258.   Number_Of_Runs = 0;
  259. }
  260.  
  261. void main (argc, argv)
  262. int argc;
  263. char **argv;
  264. /*****/
  265.  
  266.   /* main program, corresponds to procedures        */
  267.   /* Main and Proc_0 in the Ada version             */
  268. {
  269.   printf ("\n");
  270.   printf ("Dhrystone Benchmark, Version 2.1 (Language: C)\n");
  271.   printf ("\n");
  272.   if (Reg)
  273.   {
  274.     printf ("Program compiled with 'register' attribute\n");
  275.     printf ("\n");
  276.   }
  277.   else
  278.   {
  279.     printf ("Program compiled without 'register' attribute\n");
  280.     printf ("\n");
  281.   }
  282.  
  283.   if ( argc == 1 )
  284.   {
  285. #ifdef DURATION
  286.     printf ("Execution starts, runs through Dhrystone for %d seconds\n", DURATION);
  287.     Number_Of_Runs = -1;
  288. #ifdef OS2TMR
  289.     start_alarm(DURATION);
  290. #else
  291.     signal(SIGALRM, alarm_handler);
  292.     alarm(DURATION);
  293. #endif
  294. #else
  295.     printf ("Please give the number of runs through the benchmark: ");
  296.     {
  297.       unsigned long n;
  298.       scanf ("%lu", &n);
  299.       Number_Of_Runs = n;
  300.     }
  301.     printf ("\n");
  302.     printf ("Execution starts, %lu runs through Dhrystone\n", Number_Of_Runs);
  303. #endif
  304.   }
  305.   else
  306.   {
  307.     extern long atol();
  308.     Number_Of_Runs = atol(argv[1]);
  309.     printf ("Execution starts, %lu runs through Dhrystone\n", Number_Of_Runs);
  310.   }
  311.  
  312.   User_Time = dhry_stone();
  313.  
  314.   if (User_Time == 0)
  315.   {
  316.     printf ("Data consistency error\n");
  317.     exit(1)